package com.bgs.controller;

import com.bgs.pojo.E;
import com.bgs.pojo.Exam;
import com.bgs.pojo.ExamB;
import com.bgs.pojo.studentInformation;
import com.bgs.pojo.vo.ExamVo;
import com.bgs.pojo.vo.studentInformationVO;
import com.bgs.service.ExamService;
import com.bgs.utils.MyContent;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Auther: 梁玉杰
 * @Date: 2021/9/6 08:36
 * @Description: TODO
 */
@Controller
public class ExamController {

        Logger log = LogManager.getLogger();


    @Autowired
    private ExamService examService;

    //全查+模糊差------新技术（因为需要返回map集合，但是呢，不推荐用map）
    @RequestMapping("/ExamfindAllormodil")
    @ResponseBody
    public Map<String,Object> ExamfindAllormodil(@RequestBody ExamVo eVO){




        //模糊查询前端传过来的数据
        log.info("模糊查询前端传过来的数据studentInformationVO"+eVO);
        Map<String,Object> m = new HashMap<>();

        List<E> e = new ArrayList<E>();

        //调用分页查询账单类列表的方法s
        //设置分页信息(当前页码，每页显示数量)
        PageHelper.startPage(eVO.getPage(),eVO.getLimit());
        List<Exam> slist = examService.findAll();
        List<ExamB> s = examService.findAllB();

        for (int i = 0; i < slist.size()-1; i++) {
             Exam eA = slist.get(i);

//            List<ExamB> s = examService.findAll();

//            for (int n = 0; n < s.size(); n++) {
            for (int n = i+1; n < s.size(); n++) {
                ExamB eB = s.get(n);
                final Integer eAa = eA.getAge();
                final Integer eBa = eB.getAge();
//                if (!(eAa.equals(eBa)) ) {
                     E e1 = new E();
                     e1.setApkId(eA.getPkId());
                     e1.setAname(eA.getName());
                     e1.setAsex(eA.getSex());
                     e1.setAage(eA.getAge());

                     e1.setBpkId(eB.getPkId());
                     e1.setBname(eB.getName());
                     e1.setBsex(eB.getSex());
                     e1.setBage(eB.getAge());

                    Integer ege = (e1.getAage()-e1.getBage());
                    e1.setEge(ege);
                    e.add(e1);
//                }
            }

        }


        for (int l = 0; l < e.size(); l++) {
            System.out.println("eee"+e.get(l));
        }


        //创建分页对象
//        PageInfo<E> pageInfo = new PageInfo<E>(e);
        // JSONObject jsonObj = JSONObject.parseObject(sJson);
        // m = jsonObj; json对象转成map
        log.info("List<E>:::"+e);
        m.put(MyContent.CODE,0);
        m.put(MyContent.MSG,"查询成功！");
        m.put(MyContent.COUNT,e.size());
        m.put(MyContent.DATA,e);


        return m;
    }


    //全查+模糊差------新技术（因为需要返回map集合，但是呢，不推荐用map）
    @RequestMapping("/ExamfindAllormodil2")
    @ResponseBody
    public Map<String,Object> ExamfindAllormodil2(@RequestBody ExamVo eVO){

        //模糊查询前端传过来的数据
        log.info("模糊查询前端传过来的数据studentInformationVO"+eVO);
        Map<String,Object> m = new HashMap<>();

        List<E> e = new ArrayList<E>();

        //调用分页查询账单类列表的方法s
        //设置分页信息(当前页码，每页显示数量)
//        PageHelper.startPage(eVO.getPage(),eVO.getLimit());
        List<Exam> slist = examService.findAll2();
        List<ExamB> s = examService.findAllB();

        for (int i = 0; i < slist.size()-1; i++) {
             Exam eA = slist.get(i);

//            List<ExamB> s = examService.findAll();

//            for (int n = 0; n < s.size(); n++) {
            for (int n = i+1; n < s.size(); n++) {
                ExamB eB = s.get(n);
                final Integer eAa = eA.getAge();
                final Integer eBa = eB.getAge();
//                if (!(eAa.equals(eBa)) ) {
                     E e1 = new E();
                     e1.setApkId(eA.getPkId());
                     e1.setAname(eA.getName());
                     e1.setAsex(eA.getSex());
                     e1.setAage(eA.getAge());

                     e1.setBpkId(eB.getPkId());
                     e1.setBname(eB.getName());
                     e1.setBsex(eB.getSex());
                     e1.setBage(eB.getAge());

                    Integer ege = (e1.getAage()-e1.getBage());
                    e1.setEge(ege);
                    e.add(e1);
//                }
            }

        }

        log.info("List<E>:::"+e);
        m.put(MyContent.CODE,0);
        m.put(MyContent.MSG,"查询成功！");
        m.put(MyContent.COUNT,e.size());
        m.put(MyContent.DATA,e);


        return m;
    }


}
